package pt.mauromad.guias.dao.manifest;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import pt.mauromad.guias.dao.AddressDao;
import pt.mauromad.guias.dao.UserDao;
import pt.mauromad.guias.refdata.DocumentType;

@Entity
@Table(name = "manifest")
public class ManifestDao {
	private Long id;
	private Date creationDate;
	private UserDao owner;
	private DocumentType documentType;
	private AddressDao originAddress;
	private AddressDao destinationAddress;
	private AddressDao shippingAddress;
	private AddressDao deliveryAddress;
	private String vehicleId;
	private Date startDate;
	private Date endDate;
	private List<ManifestItemDao> items;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(columnDefinition = "date default sysdate", insertable = false, updatable = false, nullable = false)
	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	@ManyToOne(cascade = CascadeType.DETACH, optional = false)
	@JoinColumn(name = "owner_id", insertable = true, updatable = false, nullable = false)
	public UserDao getOwner() {
		return owner;
	}

	public void setOwner(UserDao owner) {
		this.owner = owner;
	}

	public DocumentType getDocumentType() {
		return documentType;
	}

	public void setDocumentType(DocumentType documentType) {
		this.documentType = documentType;
	}

	@ManyToOne(cascade = CascadeType.DETACH, optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "origin_address_id")
	public AddressDao getOriginAddress() {
		return originAddress;
	}

	public void setOriginAddress(AddressDao originAddress) {
		this.originAddress = originAddress;
	}

	@ManyToOne(cascade = CascadeType.DETACH, optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "destination_address_id")
	public AddressDao getDestinationAddress() {
		return destinationAddress;
	}

	public void setDestinationAddress(AddressDao destinationAddress) {
		this.destinationAddress = destinationAddress;
	}

	@ManyToOne(cascade = CascadeType.DETACH, optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "shipping_address_id", nullable = false)
	public AddressDao getShippingAddress() {
		return shippingAddress;
	}

	public void setShippingAddress(AddressDao shippingAddress) {
		this.shippingAddress = shippingAddress;
	}

	@ManyToOne(cascade = CascadeType.DETACH, optional = false, fetch = FetchType.EAGER)
	@JoinColumn(name = "delivery_address_id", nullable = false)
	public AddressDao getDeliveryAddress() {
		return deliveryAddress;
	}

	public void setDeliveryAddress(AddressDao deliveryAddress) {
		this.deliveryAddress = deliveryAddress;
	}

	public String getVehicleId() {
		return vehicleId;
	}

	public void setVehicleId(String vehicleId) {
		this.vehicleId = vehicleId;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "manifest", orphanRemoval = true)
	public List<ManifestItemDao> getItems() {
		return items;
	}

	public void setItems(List<ManifestItemDao> items) {
		this.items = items;
	}
}
